#ifndef __wifi_H__
#define __wifi_H__

#include "stdbool.h"

#define AT_CIPCLOSE "AT+CIPCLOSE\r\n"
#define AT_CIPCLOSE_RES "OK"
#define AT_RST "AT+RST\r\n"
#define AT_RST_RES "OK"
#define AT_CIPSTART "AT+CIPSTART=\"TCP\",\"139.196.170.68\",9501,50\r\n"
#define AT_CIPSTART_RES "CONNECT"
#define AT_CIPHTTP "AT+CIPSTART=\"TCP\",\"loracall.jiazi-iot.com\",80,50\r\n"
#define AT_CIPHTTPN "AT+CIPSTART=\"TCP\",\"172x37669j.51mypc.cn\",21523,50\r\n"
#define AT_CIPHTTP_RES "CONNECT"
#define AT_CIPMQTT \
  "AT+CIPSTART=\"TCP\",\"loracall.jiazi-iot.com\",1883,50\r\n"  //"AT+CIPSTART=\"TCP\",\"172x37669j.51mypc.cn\",34204,50\r\n"//"AT+CIPSTART=\"TCP\",\"172x37669j.51mypc.cn\",34204,50\r\n"//
#define AT_CIPMQTT_RES "CONNECT"
#define AT_CWMODE_DEF "AT+CWMODE_DEF=1\r\n"
#define AT_CWMODE_DEF_RES "OK"
#define AT_CWAUTOCONN "AT+CWAUTOCONN=1\r\n"
#define AT_CWAUTOCONN_RES "OK"
#define AT_CIPDNS "AT+CIPDNS_CUR=1,\"114.114.114.114\"\r\n"
#define AT_CIPDNS_RES "OK"
#define AT_STATUS "AT+CIPSTATUS\r\n"

#define AT_CWSTARTDISCOVER "AT+CWSTARTDISCOVER=\"%15s\",\"%15s_%16s\",1\r\n"
#define AT_CWSTARTDISCOVER_RES "OK"

#define AT_OUTTRANS "AT+CIPMODE=0\r\n "
#define AT_OUTTRANS_RES "OK"
#define AT_ENTERTRANS "AT+CIPMODE=1\r\n "
#define AT_ENTERTRANS_RES "OK"
#define AT_SINGLELINK "AT+CIPMUX=0\r\n "
#define AT_SINGLELINK_RES "OK"
#define AT_TRANSSEND "AT+CIPSEND\r\n "
#define AT_TRANSSEND_RES ">"

#define AT_CWSTOPSMART "AT+CWSTOPSMART\r\n"
#define AT_CWSTOPSMART_RES "OK"
#define AT_CWSTARTSMART "AT+CWSTARTSMART=2\r\n"
#define AT_CWSTARTSMART_RES "OK"
#define AT_CONNECT_RES "Smart get wifi info"  //"connected"

enum {
  WIFI_REV_OK = 0,   //接收完成标志
  WIFI_REV_WAIT = 1  //接收未完成标志
};

typedef enum {
  Wifi_None = 0,     //无设备
  Wifi_GoTIP = 1,    //连接路由器
  Wifi_Conn = 2,     //连接服务器
  Wifi_DisConn = 3,  //断开连接服务器
  Wifi_Lost = 4,     //未连接路由器
} eWifiInfo;

unsigned char Wifi_WaitRecive(void);
unsigned char Wifi_Connect(void);
unsigned char Wifi_ReConnect(void);

unsigned char Wifi_Connect_Server(char *ip, unsigned int port);
void Wifi_SendData(unsigned char *data, int len);
unsigned char *Wifi_GetIPD(unsigned int timeOut);
void Wifi_ClearRecive(void);
unsigned char Wifi_DisConnect(void);

void Wifi_EnterTrans(void);
void Wifi_QuitTrans(void);
unsigned char Wifi_Reset(void);
void Wifi_Check(void);
eWifiInfo Wifi_CheckNet(void);

#endif
